{% extends "base.html" %}

{% block title %}编辑参数 - 告警系统{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="mb-1"><i class="bi bi-pencil-square me-2"></i>编辑参数</h2>
            <p class="text-muted mb-0">修改系统参数配置</p>
        </div>
        <div class="d-flex align-items-center gap-3">
            <!-- MQTT状态指示器 -->
            <div class="d-flex align-items-center">
                <span class="me-2">MQTT:</span>
                {% if mqtt_connected %}
                <span class="badge bg-success rounded-pill">
                    <i class="bi bi-plug me-1"></i> 已连接
                </span>
                {% else %}
                <span class="badge bg-danger rounded-pill">
                    <i class="bi bi-plug-fill me-1"></i> 未连接
                </span>
                {% endif %}
            </div>
        </div>
    </div>

    {% if error %}
    <div class="alert alert-danger alert-dismissible fade show mb-4">
        <i class="bi bi-exclamation-circle me-2"></i> {{ error }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    {% endif %}

    <div class="card shadow-sm">
        <div class="card-body">
            <form method="post" action="/update_parameter/{{ parameter.ParameterId }}">
                <div class="row g-3 mb-4">
                    <div class="col-md-6">
                        <label class="form-label">参数ID</label>
                        <input type="text" class="form-control" value="{{ parameter.ParameterId }}" readonly>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">创建时间</label>
                        <input type="text" class="form-control" 
                               value="{{ parameter.CreateTime.strftime('%Y-%m-%d %H:%M') if parameter.CreateTime else '未知' }}" 
                               readonly>
                    </div>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">参数名称 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" name="ParameterName" 
                           value="{{ parameter.ParameterName }}" required>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">设备参数名称</label>
                    <input type="text" class="form-control" name="DeviceParameter" 
                           value="{{ parameter.DeviceParameter or '' }}">
                    <small class="text-muted">设备端使用的参数名称，如果为空则使用参数名称</small>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">参数值 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" name="ParameterValue" 
                           value="{{ parameter.ParameterValue }}" required>
                </div>
                
                <div class="mb-4">
                    <label class="form-label">参数描述</label>
                    <textarea class="form-control" name="ParameterDescription" rows="4">{{ parameter.ParameterDescription or '' }}</textarea>
                </div>
                
                <div class="d-flex justify-content-end gap-3">
                    <a href="/parameterconfig" class="btn btn-secondary">取消</a>
                    <button type="submit" class="btn btn-primary">保存更改</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    // 此部分不再需要，已移除
});
</script>
{% endblock %}